
from wxauto import WeChat
import time
import requests
import datetime
import pyautogui, sys
# from datetime import datetime
# from datetime import date
from apscheduler.schedulers.blocking import BlockingScheduler

def get_news():
 
    """获取金山词霸每日一句，英文和翻译"""
    url = "http://open.iciba.com/dsapi/"
    r = requests.get(url)
    content = r.json()['content']
    note = r.json()['note']
    return content, note

def get_love():
    url2 = 'https://api.uomg.com/api/rand.qinghua?format=json'
    r2 = requests.get(url2)
    content2 = r2.json()['content']
    return content2

def main():
    curr_time = datetime.datetime.now()
    time_str = datetime.datetime.strftime(curr_time,'%Y-%m-%d %H:%M:%S')
    print('请输入发送人的备注：')
    who = '宝贝主人么么哒'

    print("请输入推迟打开微信时间(s):")
    t_delay1 = int(3)

    print("请输入推迟发送时间(s):")
    t_delay2 = int(2)

    print("请选择发送消息还是文件:1.消息, 2.文件。输入1或2。")
    chattype = int(1)

    if chattype == 1:
        print("请输入发送的消息：")
        chat_message = get_news()
        chat_message2 = get_love()
    elif chattype == 2:
        print("请输入文件的路径：")
        chat_file_path = input()

    time.sleep(t_delay1)    #推迟打开微信时间

    pyautogui.click(2559,1418)      #返回桌面---此处需要自己获取位置
    pyautogui.doubleClick(1533,1271)  #打开微信---此处需要自己获取位置

    wx = WeChat()  #获取当前微信客户端

    wx.GetSessionList()     # 获取会话列表
    wx.ChatWith(who)

    time.sleep(t_delay2)    #推迟发送时间

    if chattype == 1:
        # wx.SendMsg(chat_message[0])
        # wx.SendMsg(chat_message[1])
        wx.SendMsg('小李子提醒你：现在是'+time_str+'该起来喝口水，该活动活动，看看远方.'+chat_message2)
    elif chattype == 2:
        wx.SendFiles(chat_file_path)

main()
# scheduler = BlockingScheduler() # 实例化
# # 在 2020-08-28 15:43:00至2020-08-28 15:50:00期间，每隔1分30秒 运行一次 job 方法
# scheduler.add_job(main, 'interval', minutes=1, seconds = 1, start_date='2022-05-13 10:00:00', end_date='2023-05-13 10:50:00')
# scheduler.start()
# scheduler.add_job(job, "interval", seconds=10,id='job')
# scheduler.add_job(main, "interval", seconds=10,id='main')
# scheduler.start()
# scheduler.shutdown()

# 获取坐标
# from turtle import position
# import pyautogui, sys
# print("press ctrl-c to quit.")
# try:
#     while True:
#         x, y = pyautogui.position()
#         positionStr = "X: " + str(x).rjust(4) + "Y: " + str(y).rjust(4)
#         print(positionStr, end="")
#         print("\b" * len(positionStr),end="", flush=True)
# except KeyboardInterrupt:
#     print('\n')
# pyinstaller -F -w -i 
    